package com.yupi.springbootinit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.model.entity.Post;
import com.yupi.springbootinit.model.entity.Systeminfo;
import com.yupi.springbootinit.service.SysteminfoService;
import com.yupi.springbootinit.mapper.SysteminfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
* @author LENOVO
* @description 针对表【systeminfo】的数据库操作Service实现
* @createDate 2025-01-24 06:58:40
*/
@Service
public class SysteminfoServiceImpl extends ServiceImpl<SysteminfoMapper, Systeminfo>
    implements SysteminfoService{

    @Resource
    private SysteminfoMapper systeminfoMapper;

    /**
     * 删除三个月前的数据
     * @return
     */
    @Override
    public boolean deleteOldInfo() {
        LocalDateTime threeMonthAgo = LocalDateTime.now().minusMonths(3);
        QueryWrapper<Systeminfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lt("createTime", threeMonthAgo);
        List<Systeminfo> systeminfos = systeminfoMapper.selectList(queryWrapper);
        if (systeminfos.isEmpty()) {
            throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "没有过期的数据");
        }
        return systeminfoMapper.deleteBatchIds(systeminfos) > 0;
    }
}




